<%--
  Created by IntelliJ IDEA.
  User: 风间琉璃
  Date: 2021/9/3
  Time: 17:04
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>新增</title>
</head>
<body>
    <h1>添加联系人</h1>
    <form class="myform" method="post" action="${pageContext.request.contextPath}/contact/add">
        <table>
            <tr>
                <td>姓名：</td>
                <td>
                    <label>
                        <input class="cname" name="cname" type="text"/>
                    </label>
                </td>
            </tr>
            <tr>
                <td>手机：</td>
                <td>
                    <label>
                        <input class="mobile" name="mobile" type="text"/>
                    </label>
                </td>
            </tr>
            <tr>
                <td>QQ：</td>
                <td>
                    <label>
                        <input class="qq" name="qq" type="text"/>
                    </label>
                </td>
            </tr>
            <tr>
                <td>Email：</td>
                <td>
                    <label>
                        <input class="email" name="email" type="text"/>
                    </label>
                </td>
            </tr>
            <tr>
                <td>地址：</td>
                <td>
                    <label>
                        <input class="address" name="address" type="text"/>
                    </label>
                </td>
            </tr>
        </table>
        <button type="submit">保存</button>
        <button type="reset">重置</button>
    </form>
    <br/>
    <span class="msg">${msg}</span>
    <script src="${pageContext.request.contextPath }/statics/js/jquery-1.8.3.js"></script>
    <script>
        $(document).ready(function (){
            var msg = $(".msg");
            setTimeout(function (){
                msg.hide();
            },3000);
            $(".myform").submit(function (){
                var cname = $(".cname").val();
                var mobile = $(".mobile").val();
                var qq = $(".qq").val();
                var email = $(".email").val();
                var address = $(".address").val();

                var myreg =/^[1][3,4,5,7,8][0-9]{9}$/;
                var myreg1 = /^[1-9][0-9]{4,9}$/gim;
                var myreg2 = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
                if (cname == "" || cname == null){
                    alert("必须填写联系人姓名！");
                    return false;
                }
                if (!myreg.test(mobile)) {
                    alert("请正确填写手机号！");
                    return false;
                }
                if (!myreg1.test(qq)) {
                    alert("请正确填写QQ！");
                    return false;
                }
                if (!myreg2.test(email)) {
                    alert("请正确填写邮箱！");
                    return false;
                }
                return true;
            })
        })
    </script>
</body>
</html>
